package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.SysAdminUserProject;
import com.ruoyi.system.mapper.SysAdminUserProjectMapper;
import com.ruoyi.system.service.ISysAdminUserProjectService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wux
 * @date 2023/5/15 15:44
 */
@Service
public class SysAdminUserProjectServiceImpl extends ServiceImpl<SysAdminUserProjectMapper, SysAdminUserProject> implements ISysAdminUserProjectService {
    @Override
    public void saveList(List<Long> projectIdList, Long userId) {
        List<SysAdminUserProject> userProjectList = projectIdList.stream().map(item -> {
            SysAdminUserProject userProject = new SysAdminUserProject();
            userProject.setUserId(userId);
            userProject.setProjectId(item);
            return userProject;
        }).collect(Collectors.toList());
        this.remove(new LambdaQueryWrapper<SysAdminUserProject>().eq(SysAdminUserProject :: getUserId,userId));
        this.saveBatch(userProjectList);
    }
}
